<?php defined( 'BASEPATH' ) or die( 'Restricted' );

/* This code is Copyright (C) by TMLA INC  ALL RIGHTS RESERVED. */
class achRecordFactory extends tgsfBase
{
	public static function iatEntryDetail( )
	{
		$ob = new iatDetailRecord();
		$ob
		// Record Type Code
		->addItem
		(
			arbItemFactory::padLeft( 0 )
			->length( 1 )->enforceLength()
			->enforceNumeric()
			->staticValue( artcENTRY_DETAIL )
		)
		// Transaction Code
		->addItem
		(
			arbItemFactory::padLeft( 0 )
			->length( 2 )->enforceLength()
			->enforceNumeric()
			->fieldName( 'ach_txn_transaction_code' )
		)
		// Gateway Operator Identification / Receiving DFI Identification ( routing and check digit together - fields 3 and 4)
		->addItem
		(
			arbItemFactory::padLeft()
			->length( 9 )->enforceLength()
			->enforceNumeric()
			->fieldName( 'ach_txn_go_receiving_dfi_id' )
		)
		// Total number of addenda records for this Entry Detail Record, right justify, zero fill
		->addItem
		(
			arbItemFactory::padLeft( 0 )
			->length( 4 )
			->fieldName( '__addendaRecordCount' )
		)
		// Reserved, leave blank
		->addItem
		(
			arbItemFactory::padLeft()
			->length( 13 )
			->staticValue( ' ' )
		)
		// Amount (in ORIGINATION denomination, e.g. USD)
		->addItem
		(
			arbItemFactory::padLeft( 0 )
			->length( 10 )
			->enforceNumeric()
			->formatCurrency()
			->fieldName( 'ach_txn_amount' )
		)
		// Foreign Receiver's Account Number / DFI Account Number
		->addItem
		(
			arbItemFactory::padRight()
			->length( 35 )
			->fieldName( 'ach_txn_external_account_number' )
		)

		// Reserved, leave blank
		->addItem
		(
			arbItemFactory::padLeft()
			->length( 2 )
			->staticValue( ' ' )
		)
		// Gateway Operator OFAC Screening Indicator
		// For now we will leave this blank, but may change it if we need to do OFAC screening ourselves
		->addItem
		(
			arbItemFactory::padLeft()
			->length( 1 )
			->staticValue( ' ' )
		)
		// Secondary Gateway Operator OFAC Screening Indicator
		// For now we will leave this blank, but may change it if we need to do OFAC screening ourselves
		->addItem
		(
			arbItemFactory::padLeft()
			->length( 1 )
			->staticValue( ' ' )
		)
		// Addenda record indicator, should always be '1' because IAT's require a minimum of 7 addendas
		->addItem
		(
			arbItemFactory::padLeft()
			->length( 1 )
			->enforceNumeric()
			->staticValue( '1' )
		)
		// Trace Number - this is the batch count, just like the PPD
		->addItem
		(
			// Trace Number
			arbItemFactory::padLeft()
			->length( 15 )
			->fieldName( 'ach_txn_trace_number' )
		);
		return $ob;		
	}
	
	public static function iatFirstAddenda( )
	{
		$ob = new iatAddendaRecord();
		$ob
		// Record Type Code
		->addItem
		(
			arbItemFactory::padLeft( 0 )
			->length( 1 )
			->enforceNumeric()
			->staticValue( artcADDENDA )
		)
		->addItem
		// Addenda Type Code
		(
			arbItemFactory::padLeft( )
			->length( 2 )
			->enforceNumeric()
			->staticValue( aatcIAT_FIRST )
		)
		// Transaction Type Code
		->addItem
		(
			arbItemFactory::padLeft( )
			->length( 3 )->enforceLength()
			->fieldName( 'ach_txn_transaction_type_code' )
		)
		// Foreign Payment Amount (set to zero when foreign_exchange_indicator set to FV, foreign currency amount when set to FF)
		->addItem
		(
			arbItemFactory::padLeft( 0 )
			->length( 18 )
			->enforceNumeric()
			->formatCurrency()
			->staticValue( '0' )
			// ->fieldName( 'ach_txn_amount' ) // Its not ach_txn_amount - We currently use FV, and don't have a foreign currency amount.
		)
		// Foreign Trace Number
		->addItem
		(
			arbItemFactory::padLeft()
			->length( 22 )
			->staticValue( ' ' )
		)
		// Receiving Company Name or Individual Name
		->addItem
		(
			arbItemFactory::padRight()
			->length( 35 )
			->fieldName( 'ach_txn_external_account_holder' )
		)
		// Reserved, leave blank
		->addItem
		(
			arbItemFactory::padLeft()
			->length( 6 )
			->staticValue( ' ' )
		)
		// Entry Detail Sequence Number
		// e.g. Trace Number - this is the batch count, but we only use the last seven digits
		->addItem
		(
			// Trace Number
			arbItemFactory::padLeft()
			->length( 7 )
			->fieldName( 'ach_txn_trace_number' )
			->truncateLeft( 7 ) // truncate everything to the left, leaving the 7 right-most digits
		);

		return $ob;		

	}

	public static function iatSecondAddenda( )
	{
		$ob = new iatAddendaRecord();
		$ob
		// Record Type Code
		->addItem
		(
			arbItemFactory::padLeft( 0 )
			->length( 1 )
			->enforceNumeric()
			->staticValue( artcADDENDA )
		)
		->addItem
		// Addenda Type Code
		(
			arbItemFactory::padLeft( )
			->length( 2 )
			->enforceNumeric()
			->staticValue( aatcIAT_SECOND )
		)
		// Originator Name
		->addItem
		(
			arbItemFactory::padRight()
			->length( 35 )
			->fieldName( '__achOriginatorName' )
		)
		// Originator Street Address
		->addItem
		(
			arbItemFactory::padRight()
			->length( 35 )
			->fieldName( '__achOriginatorStreetAddress' )
		)
		// Reserved, leave blank
		->addItem
		(
			arbItemFactory::padLeft()
			->length( 14 )
			->staticValue( ' ' )
		)
		// Entry Detail Sequence Number
		// e.g. Trace Number - this is the batch count, but we only use the last seven digits
		->addItem
		(
			// Trace Number
			arbItemFactory::padLeft()
			->length( 7 )
			->fieldName( 'ach_txn_trace_number' )
			->truncateLeft( 7 ) // truncate everything to the left, leaving the 7 right-most digits
		);
		return $ob;		

	}

	public static function iatThirdAddenda( )
	{
		$ob = new iatAddendaRecord();
		$ob
		// Record Type Code
		->addItem
		(
			arbItemFactory::padLeft( 0 )
			->length( 1 )
			->enforceNumeric()
			->staticValue( artcADDENDA )
		)
		->addItem
		// Addenda Type Code
		(
			arbItemFactory::padLeft( )
			->length( 2 )
			->enforceNumeric()
			->staticValue( aatcIAT_THIRD )
		)
		// Originator City and State/Province (spearated by asterisk, ends in backslash, e.g. "Kansas City*MO\"
		->addItem
		(
			arbItemFactory::padRight()
			->length( 35 )
			->concatFields( array( '__achOriginatorCity', '__achOriginatorState' ), '*' )
			->appendValue( "\\" )
		)
		// Originator Country and Postal Code (separated by asterisk, ends in backslash, e.g. "US*64105\"
		->addItem
		(
			arbItemFactory::padRight()
			->length( 35 )
			->concatFields( array( '__achOriginatorCountry', '__achOriginatorPostalCode' ), '*' )
			->appendValue( "\\" )
		)
		// Reserved, leave blank
		->addItem
		(
			arbItemFactory::padLeft()
			->length( 14 )
			->staticValue( ' ' )
		)
		// Entry Detail Sequence Number
		// e.g. Trace Number - this is the batch count, but we only use the last seven digits
		->addItem
		(
			// Trace Number
			arbItemFactory::padLeft()
			->length( 7 )
			->fieldName( 'ach_txn_trace_number' )
			->truncateLeft( 7 ) // truncate everything to the left, leaving the 7 right-most digits
		);

		return $ob;		

	}

	public static function iatFourthAddenda( )
	{
		$ob = new iatAddendaRecord();
		$ob
		// Record Type Code
		->addItem
		(
			arbItemFactory::padLeft( 0 )
			->length( 1 )
			->enforceNumeric()
			->staticValue( artcADDENDA )
		)
		->addItem
		// Addenda Type Code
		(
			arbItemFactory::padLeft( )
			->length( 2 )
			->enforceNumeric()
			->staticValue( aatcIAT_FOURTH )
		)
		// Originating DFI Name
		->addItem
		(
			arbItemFactory::padRight()
			->length( 35 )
			->fieldName( '__achOriginatingDFIName' )
		)
		// Originating DFI Identification Number Qualifier
		->addItem
		(
			arbItemFactory::padRight()
			->length( 2 )
			->fieldName( '__achOriginatingDFIIdQualifier' )
		)
		// Originating DFI Identification
		->addItem
		(
			arbItemFactory::padRight()
			->length( 34 )
			->fieldName( '__achOriginatingDFIId' )
		)
		// Originating DFI Branch Country Code
		->addItem
		(
			arbItemFactory::padRight()
			->length( 3 )
			->fieldName( '__achOriginatingDFIBranchCountryCode' )
		)
		// Reserved, leave blank
		->addItem
		(
			arbItemFactory::padLeft()
			->length( 10 )
			->staticValue( ' ' )
		)
		// Entry Detail Sequence Number
		// e.g. Trace Number - this is the batch count, but we only use the last seven digits
		->addItem
		(
			// Trace Number
			arbItemFactory::padLeft()
			->length( 7 )
			->fieldName( 'ach_txn_trace_number' )
			->truncateLeft( 7 ) // truncate everything to the left, leaving the 7 right-most digits
		);

		return $ob;		

	}

	public static function iatFifthAddenda( )
	{
		$ob = new iatAddendaRecord();
		$ob
		// Record Type Code
		->addItem
		(
			arbItemFactory::padLeft( 0 )
			->length( 1 )
			->enforceNumeric()
			->staticValue( artcADDENDA )
		)
		->addItem
		// Addenda Type Code
		(
			arbItemFactory::padLeft( )
			->length( 2 )
			->enforceNumeric()
			->staticValue( aatcIAT_FIFTH )
		)
		// Receiving DFI Name
		->addItem
		(
			arbItemFactory::padRight()
			->length( 35 )
			->fieldName( 'ach_txn_receiving_dfi_name' )
		)
		// Receiving DFI Identification Number Qualifier
		->addItem
		(
			arbItemFactory::padRight()
			->length( 2 )
			->fieldName( 'ach_txn_receiving_dfi_id_qualifier' )
		)
		// Receiving DFI Identification
		->addItem
		(
			arbItemFactory::padRight()
			->length( 34 )
			->fieldName( 'ach_txn_external_account_routing' )
		)
		// Originating DFI Branch Country Code
		->addItem
		(
			arbItemFactory::padRight()
			->length( 3 )
			->fieldName( 'ach_txn_receiving_dfi_country' )
		)
		// Reserved, leave blank
		->addItem
		(
			arbItemFactory::padLeft()
			->length( 10 )
			->staticValue( ' ' )
		)
		// Entry Detail Sequence Number
		// e.g. Trace Number - this is the batch count, but we only use the last seven digits
		->addItem
		(
			// Trace Number
			arbItemFactory::padLeft()
			->length( 7 )
			->fieldName( 'ach_txn_trace_number' )
			->truncateLeft( 7 ) // truncate everything to the left, leaving the 7 right-most digits
		);

		return $ob;		

	}


	public static function iatSixthAddenda( )
	{
		$ob = new iatAddendaRecord();
		$ob
		// Record Type Code
		->addItem
		(
			arbItemFactory::padLeft( 0 )
			->length( 1 )
			->enforceNumeric()
			->staticValue( artcADDENDA )
		)
		->addItem
		// Addenda Type Code
		(
			arbItemFactory::padLeft( )
			->length( 2 )
			->enforceNumeric()
			->staticValue( aatcIAT_SIXTH )
		)
		// Receiver Identification Number - this is the equivalent of the PPD Company internal ID, a company assigned trace number
		// we use the ach_txn_id with an A prepended
		->addItem
		(
			arbItemFactory::padRight()
			->length( 15 )
			->prependValue( 'A' )
			->fieldName( 'ach_txn_id' )
		)
		// Receiver Street Address
		->addItem
		(
			arbItemFactory::padRight()
			->length( 35 )
			->fieldName( 'ach_txn_receiver_address' )
		)
		// Reserved, leave blank
		->addItem
		(
			arbItemFactory::padLeft()
			->length( 34 )
			->staticValue( ' ' )
		)
		// Entry Detail Sequence Number
		// e.g. Trace Number - this is the batch count, but we only use the last seven digits
		->addItem
		(
			// Trace Number
			arbItemFactory::padLeft()
			->length( 7 )
			->fieldName( 'ach_txn_trace_number' )
			->truncateLeft( 7 ) // truncate everything to the left, leaving the 7 right-most digits
		);

		return $ob;		

	}

	public static function iatSeventhAddenda( )
	{
		$ob = new iatAddendaRecord();
		$ob
		// Record Type Code
		->addItem
		(
			arbItemFactory::padLeft( 0 )
			->length( 1 )
			->enforceNumeric()
			->staticValue( artcADDENDA )
		)
		->addItem
		// Addenda Type Code
		(
			arbItemFactory::padLeft( )
			->length( 2 )
			->enforceNumeric()
			->staticValue( aatcIAT_SEVENTH )
		)
		// Receiver City and State/Province (spearated by asterisk, ends in backslash, e.g. "Saskatoon*SK\"
		->addItem
		(
			arbItemFactory::padRight()
			->length( 35 )
			->concatFields( array( 'ach_txn_receiver_city', 'ach_txn_receiver_state' ), '*' )
			->appendValue( "\\" )
		)
		// Receiver Country and Postal Code (separated by asterisk, ends in backslash, e.g. "CA*A1A 2B2\"
		->addItem
		(
			arbItemFactory::padRight()
			->length( 35 )
			->concatFields( array( 'ach_txn_receiver_country', 'ach_txn_receiver_postal_code' ), '*' )
			->appendValue( "\\" )
		)
		// Reserved, leave blank
		->addItem
		(
			arbItemFactory::padLeft()
			->length( 14 )
			->staticValue( ' ' )
		)
		// Entry Detail Sequence Number
		// e.g. Trace Number - this is the batch count, but we only use the last seven digits
		->addItem
		(
			// Trace Number
			arbItemFactory::padLeft()
			->length( 7 )
			->fieldName( 'ach_txn_trace_number' )
			->truncateLeft( 7 ) // truncate everything to the left, leaving the 7 right-most digits
		);

		return $ob;

	}

	public static function returnAddenda( )
	{
		$ob = new achDetailRecord();
		$ob
		// Record Type Code
		->addItem
		(
			arbItemFactory::padLeft( 0 )
			->length( 1 )->enforceLength()
			->enforceNumeric()
			->staticValue( artcADDENDA )
		)
		->addItem
		// Addenda Type Code
		(
			arbItemFactory::padLeft( )
			->length( 2 )->enforceLength()
			->enforceNumeric()
			->staticValue( '99' )
		)
		// Return Reason Code
		->addItem
		(
			arbItemFactory::padLeft()
			->length( 3 )
			->fieldName( 'return_code' )
		)
		// Reassigned Trace Number
		->addItem
		(
			// Trace Number
			arbItemFactory::padLeft()
			->length( 15 )
			->fieldName( 'reassigned_trace_number' )
		)
		// Date of Death (only for R14 and R15)
		->addItem
		(
			arbItemFactory::padLeft( 0 )
			->length( 6 )
			->fieldName( 'date_of_death' )
		)
		// Originating Receiving DFI Identification
		->addItem
		(
			arbItemFactory::padLeft( 0 )
			->length( 8 )
			->fieldName( 'original_dfi_identification' )
		)
		// Addenda Information
		->addItem
		(
			arbItemFactory::padLeft()
			->length( 44 )
			->fieldName( 'addenda_information' )
		)
		// Entry Detail Sequence Number
		// e.g. Trace Number - this is the batch count, just like the PPD
		->addItem
		(
			// Trace Number
			arbItemFactory::padLeft()
			->length( 15 )
			->fieldName( 'ach_txn_trace_number' )
		);

		return $ob;

	}

	public static function changeAddenda( )
	{
		$ob = new achDetailRecord();
		$ob
		// Record Type Code
		->addItem
		(
			arbItemFactory::padLeft( 0 )
			->length( 1 )->enforceLength()
			->enforceNumeric()
			->staticValue( artcADDENDA )
		)
		->addItem
		// Addenda Type Code
		(
			arbItemFactory::padLeft( )
			->length( 2 )->enforceLength()
			->enforceNumeric()
			->staticValue( '98' )
		)
		// Change Code
		->addItem
		(
			arbItemFactory::padLeft()
			->length( 3 )
			->fieldName( 'change_code' )
		)
		// Reassigned Trace Number
		->addItem
		(
			// Trace Number
			arbItemFactory::padLeft()
			->length( 15 )
			->fieldName( 'reassigned_trace_number' )
		)
		// Reserved
		->addItem
		(
			arbItemFactory::padLeft( )
			->length( 6 )
			->staticValue( ' ' )
		)
		// Originating Receiving DFI Identification
		->addItem
		(
			arbItemFactory::padLeft( 0 )
			->length( 8 )
			->fieldName( 'original_dfi_identification' )
		)
		// Addenda Information
		->addItem
		(
			arbItemFactory::padLeft()
			->length( 29 )
			->fieldName( 'corrected_data' )
		)
		// Reserved
		->addItem
		(
			arbItemFactory::padLeft( )
			->length( 15 )
			->staticValue( ' ' )
		)
		// Entry Detail Sequence Number
		// e.g. Trace Number - this is the batch count, just like the PPD
		->addItem
		(
			// Trace Number
			arbItemFactory::padLeft()
			->length( 15 )
			->fieldName( 'ach_txn_trace_number' )
		);

		return $ob;

	}

	public static function ppdEntryDetail( )
	{
		$ob = new achDetailRecord();
		$ob
		->addItem
		(
			// Record Type Code
			arbItemFactory::padLeft( 0 )
			->length( 1 )->enforceLength()
			->enforceNumeric()
			->staticValue( artcENTRY_DETAIL )
		)
		// transaction
		->addItem
		(
			arbItemFactory::padLeft( 0 )
			->length( 2 )->enforceLength()
			->enforceNumeric()
			->fieldName( 'ach_txn_transaction_code' )
		)
		->addItem
		(
			arbItemFactory::padLeft()
			->length( 9 )->enforceLength()
			->enforceNumeric()
			->fieldName( 'ach_txn_external_account_routing' )
		)

		->addItem
		(
			arbItemFactory::padRight()
			->length( 17 )
			->fieldName( 'ach_txn_external_account_number' )
		)
		->addItem
		(
			arbItemFactory::padLeft( 0 )
			->length( 10 )
			->enforceNumeric()
			->formatCurrency()
			->fieldName( 'ach_txn_amount' )
		)
		->addItem
		(
			arbItemFactory::padRight()
			->length( 15 )
			->prependValue( 'A' )
			->fieldName( 'ach_txn_id' )
		)
		->addItem
		(
			arbItemFactory::padRight()
			->length( 22 )
			->fieldName( 'ach_txn_external_account_holder' )
		)
		->addItem
		(
			// Company internal code
			arbItemFactory::padLeft()
			->length( 2 )->enforceLength()
			->staticValue( '  ' )
		)
		->addItem
		(
			// this seems like it might have problems - the original code enforced the length
			// Addenda Record Indicator	Numeric
			arbItemFactory::padLeft()
			->length( 1 )->enforceLength()
			->enforceNumeric()
			->staticValue( '0' )
		)
		->addItem
		(
			// Trace Number
			arbItemFactory::padLeft()
			->length( 15 )
			->fieldName( 'ach_txn_trace_number' )
		);
		return $ob;
	}

	public static function paymentInformationAddenda( )
	{
		$ob = new achDetailRecord();
		$ob
		// Record Type Code
		->addItem
		(
			arbItemFactory::padLeft( 0 )
			->length( 1 )->enforceLength()
			->enforceNumeric()
			->staticValue( artcADDENDA )
		)
		->addItem
		// Addenda Type Code
		(
			arbItemFactory::padLeft( )
			->length( 2 )->enforceLength()
			->enforceNumeric()
			->staticValue( aatcPAYMENT_INFORMATION )
		)
		// Payment Related Information
		->addItem
		(
			arbItemFactory::padLeft()
			->length( 80 )
			->fieldName( 'payment_related_information' )
		)
		// Addenda Sequence Number
		->addItem
		(
			arbItemFactory::padLeft( )
			->length( 4 )
			->fieldName( '__addendaRecordCount' )
		)
		// e.g. Trace Number - this is the batch count, but we only use the last seven digits
		->addItem
		(
			// Trace Number
			arbItemFactory::padLeft()
			->length( 7 )
			->fieldName( 'ach_txn_trace_number' )
			->truncateLeft( 7 ) // truncate everything to the left, leaving the 7 right-most digits
		);
		
		return $ob;

	}

	public static function fileHeader( )
	{
		$ob = new achFileHeaderRecord();
		$ob
		// Record Type Code
		->addItem
		(
			arbItemFactory::padLeft( 0 )
			->length( 1 )->enforceLength()
			->enforceNumeric()
			->staticValue( artcFILE_HEADER )
		)
		// Priority Code
		->addItem
		(
			arbItemFactory::padLeft( 0 )
			->length( 2 )->enforceLength()
			->fieldName( 'ach_file_priority_code' )
		)
		// Immediate Destination ID (typically your bank's Routing Number)
		->addItem
		(
			arbItemFactory::padLeft()
			->length( 10 )
			->enforceNumeric()
			->fieldName( 'ach_file_immediate_destination' )
		)
		// Immediate Origin ID (typically your company's federal ID)
		->addItem
		(
			arbItemFactory::padLeft()
			->length( 10 )
			->enforceNumeric()
			->fieldName( 'ach_file_immediate_origin' )
		)
		// File Creation Date
		->addItem
		(
			arbItemFactory::padLeft( '0' )
			->length( 6 )->enforceLength()
			->fieldName( 'ach_file_creation_date' )
		)
		// File Creation Time
		->addItem
		(
			arbItemFactory::padLeft( '0' )
			->length( 4 )->enforceLength()
			->fieldName( 'ach_file_creation_time' )
		)
		// File ID Modifier
		->addItem
		(
			arbItemFactory::padLeft()
			->length( 1 )->enforceLength()
			->fieldName( 'ach_file_id_modifier' )
		)
		// Record Size
		->addItem
		(
			arbItemFactory::padLeft()
			->length( 3 )
			->fieldName( 'ach_file_record_size' )
		)
		// Blocking Factor
		->addItem
		(
			arbItemFactory::padLeft()
			->length( 2 )
			->fieldName( 'ach_file_blocking_factor' )
		)
		// Format Code
		->addItem
		(
			arbItemFactory::padLeft()
			->length( 1 )
			->fieldName( 'ach_file_format_code' )
		)
		// Immediate Destination Name
		->addItem
		(
			arbItemFactory::padRight()
			->length( 23 )
			->fieldName( 'ach_file_immediate_destination_name' )
		)
		// Immediate Origin Name
		->addItem
		(
			arbItemFactory::padRight()
			->length( 23 )
			->fieldName( 'ach_file_immediate_origin_name' )
		)
		// Reference Code
		->addItem
		(
			arbItemFactory::padRight()
			->length( 8 )
			->fieldName( 'ach_file_reference_code' )
		);
		return $ob;
	}


	public static function ppdBatchHeader( )
	{
		$ob = new achBatchHeaderRecord();
		$ob
		// Record Type Code
		->addItem
		(
			arbItemFactory::padLeft( 0 )
			->length( 1 )->enforceLength()
			->enforceNumeric()
			->staticValue( artcBATCH_HEADER )
		)
		// Service Class Code
		->addItem
		(
			arbItemFactory::padLeft( 0 )
			->length( 3 )->enforceLength()
			->fieldName( 'ach_batch_service_class_code' )
		)
		// Company Name
		->addItem
		(
			arbItemFactory::padRight()
			->length( 16 )
			->fieldName( 'ach_batch_company_name' )
		)
		// Discretionary Data
		->addItem
		(
			arbItemFactory::padRight()
			->length( 20 )
			->fieldName( 'ach_batch_company_disc_data' )
		)
		// Company Identification (same as header record)
		->addItem
		(
			arbItemFactory::padLeft()
			->length( 10 )
			->enforceNumeric()
			->fieldName( 'ach_batch_company_identification' )
		)
		// Standard Entry Class
		->addItem
		(
			arbItemFactory::padLeft()
			->length( 3 )->enforceLength()
			->fieldName( 'ach_batch_standard_entry_class' )
		)
		// Company Entry Description
		->addItem
		(
			arbItemFactory::padRight()
			->length( 10 )
			->fieldName( 'ach_batch_company_entry_desc' )
		)
		// Company Descriptive Date
		->addItem
		(
			arbItemFactory::padLeft( '0' )
			->length( 6 )->enforceLength()
			->fieldName( 'ach_batch_company_desc_date' )
		)
		// Effective Entry Date
		->addItem
		(
			arbItemFactory::padLeft( '0' )
			->length( 6 )->enforceLength()
			->fieldName( 'ach_batch_effective_entry_date' )
		)
		// Reserved
		->addItem
		(
			arbItemFactory::padRight()
			->length( 3 )
			->staticValue( '' )
		)
		// Originator Status Code
		->addItem
		(
			arbItemFactory::padLeft( '0' )
			->length( 1 )->enforceLength()
			->enforceNumeric()
			->fieldName( 'ach_batch_originator_status_code' )
		)
		// Originating Financial Institution routing transit number
		->addItem
		(
			arbItemFactory::padRight()
			->length( 8 )->enforceNumeric()
			->fieldName( 'ach_batch_originating_dfi_id' )
		)
		// Batch Number
		->addItem
		(
			arbItemFactory::padLeft( '0' )
			->length( 7 )->enforceNumeric()
			->fieldName( 'ach_batch_number' )
		);
		return $ob;
	}

	public static function iatBatchHeader( )
	{
		$ob = new achBatchHeaderRecord();
		$ob
		// Record Type Code
		->addItem
		(
			arbItemFactory::padLeft( )
			->length( 1 )->enforceLength()
			->enforceNumeric()
			->staticValue( artcBATCH_HEADER )
		)
		// Service Class Code
		->addItem
		(
			arbItemFactory::padLeft( )
			->length( 3 )->enforceLength()
			->fieldName( 'ach_batch_service_class_code' )
		)
		// IAT Indicator (oddly enough, the indicator is supposed to be blank)
		->addItem
		(
			arbItemFactory::padRight()
			->length( 16 )
			->staticValue( ' ' )
		)
		// 
		// Foreign Exchange Indicator (conversion methodology)
		->addItem
		(
			arbItemFactory::padRight()
			->length( 2 )
			->enforceLength()
			->fieldName( 'ach_batch_foreign_exchange_ind' )
		)
		// 
		// Foreign Exchange Reference Indicator
		->addItem
		(
			arbItemFactory::padRight()
			->length( 1 )
			->fieldName( 'ach_batch_foreign_exchange_ref_ind' )
		)
		// 
		// Foreign Exchange Reference
		->addItem
		(
			arbItemFactory::padRight()
			->length( 15 )
			->fieldName( 'ach_batch_foreign_exchange_ref' )
		)
		// 
		// ISO Destination Country Code
		->addItem
		(
			arbItemFactory::padRight()
			->length( 2 )
			->enforceLength()
			->fieldName( 'ach_batch_iso_dest_country_code' )
		)
		// Company Identification (same as header record)
		->addItem
		(
			arbItemFactory::padLeft()
			->length( 10 )
			->enforceNumeric()
			->fieldName( 'ach_batch_company_identification' )
		)
		// Standard Entry Class
		->addItem
		(
			arbItemFactory::padLeft()
			->length( 3 )->enforceLength()
			->fieldName( 'ach_batch_standard_entry_class' )
		)
		// Company Entry Description
		->addItem
		(
			arbItemFactory::padRight()
			->length( 10 )
			->fieldName( 'ach_batch_company_entry_desc' )
		)
		// ISO Originating Currency Code
		->addItem
		(
			arbItemFactory::padLeft()
			->length( 3 )->enforceLength()
			->fieldName( 'ach_batch_iso_org_currency_code' )
		)
		// ISO Destination Currency Code
		->addItem
		(
			arbItemFactory::padLeft()
			->length( 3 )->enforceLength()
			->fieldName( 'ach_batch_iso_dest_currency_code' )
		)

		// Effective Entry Date
		->addItem
		(
			arbItemFactory::padLeft( '0' )
			->length( 6 )->enforceLength()
			->fieldName( 'ach_batch_effective_entry_date' )
		)
		// Settlement Date (Inserted by ACH Operator)
		->addItem
		(
			arbItemFactory::padRight()
			->length( 3 )
			->staticValue( '' )
		)
		// Originator Status Code
		->addItem
		(
			arbItemFactory::padLeft( '0' )
			->length( 1 )->enforceLength()
			->enforceNumeric()
			->fieldName( 'ach_batch_originator_status_code' )
		)
		// Originating Financial Institution routing transit number
		->addItem
		(
			arbItemFactory::padRight()
			->length( 8 )->enforceNumeric()
			->fieldName( 'ach_batch_originating_dfi_id' )
		)
		// Batch Number
		->addItem
		(
			arbItemFactory::padLeft( '0' )
			->length( 7 )->enforceNumeric()
			->fieldName( 'ach_batch_number' )
		);
		return $ob;
	}

	public static function fileControl( )
	{
		$ob = new achFileControlRecord();
		$ob
		// Record Type Code
		->addItem
		(
			arbItemFactory::padLeft( 0 )
			->length( 1 )->enforceLength()
			->enforceNumeric()
			->staticValue( artcFILE_CONTROL )
		)
		// Batch Count
		->addItem
		(
			arbItemFactory::padLeft( '0' )
			->length( 6 )
			->fieldName( '__batchCount' )
		)
		// Block Count
		->addItem
		(
			arbItemFactory::padLeft( '0' )
			->length( 6 )
			->fieldName( '__blockCount' )
		)
		// Entry/Addenda Count
		->addItem
		(
			arbItemFactory::padLeft( '0' )
			->length( 8 )
			->fieldName( '__entryAddendaCount' )
		)
		// Entry Hash
		->addItem
		(
			arbItemFactory::padLeft( '0' )
			->length( 10 )
			//->enforceNumeric()
			->fieldName( '__entryHash' )
		)
		// Total Debit Entry Amount
		->addItem
		(
			arbItemFactory::padLeft( 0 )
			->length( 12 )
			->enforceNumeric()
			->formatCurrency()
			->fieldName( '__totalDebits' )
		)
		// Total Credit Entry Amount
		->addItem
		(
			arbItemFactory::padLeft( 0 )
			->length( 12 )
			->enforceNumeric()
			->formatCurrency()
			->fieldName( '__totalCredits' )
		)
		// Reserved
		->addItem
		(
			arbItemFactory::padLeft()
			->length( 39 )
			->staticValue( '' )
		);
		return $ob;
	}

	public static function batchControl( )
	{
		$ob = new achBatchControlRecord();
		$ob
		// Record Type Code
		->addItem
		(
			arbItemFactory::padLeft( 0 )
			->length( 1 )->enforceLength()
			->enforceNumeric()
			->staticValue( artcBATCH_CONTROL )
		)
		// Service Class Code
		->addItem
		(
			arbItemFactory::padLeft( 0 )
			->length( 3 )->enforceLength()
			->fieldName( 'ach_batch_service_class_code' )
		)
		// Entry/Addenda Count
		->addItem
		(
			arbItemFactory::padLeft( '0' )
			->length( 6 )
			->fieldName( '__entryAddendaCount' )
		)
		// Entry Hash
		->addItem
		(
			arbItemFactory::padLeft( '0' )
			->length( 10 )
			//->enforceNumeric()
			->fieldName( '__entryHash' )
		)
		// Total Debit Entry Amount
		->addItem
		(
			arbItemFactory::padLeft( 0 )
			->length( 12 )
			->enforceNumeric()
			->formatCurrency()
			->fieldName( '__totalDebits' )
		)
		// Total Credit Entry Amount
		->addItem
		(
			arbItemFactory::padLeft( 0 )
			->length( 12 )
			->enforceNumeric()
			->formatCurrency()
			->fieldName( '__totalCredits' )
		)
		// Company Identification (same as header record)
		->addItem
		(
			arbItemFactory::padLeft()
			->length( 10 )
			->enforceNumeric()
			->fieldName( 'ach_batch_company_identification' )
		)
		// Standard Entry Class
		->addItem
		(
			arbItemFactory::padLeft()
			->length( 19 )
			->staticValue( '' )
		)
		// Reserved
		->addItem
		(
			arbItemFactory::padLeft()
			->length( 6 )
			->staticValue( '' )
		)
		// Originating Financial Institution routing transit number
		->addItem
		(
			arbItemFactory::padLeft()
			->length( 8 )->enforceNumeric()
			->fieldNAme( 'ach_batch_originating_dfi_id' )
		)
		// Batch Number
		->addItem
		(
			arbItemFactory::padLeft( '0' )
			->length( 7 )->enforceNumeric()
			->fieldName( 'ach_batch_number' )
		);
		return $ob;
	}


}
